package com.baidu.cmsService.dao;

import com.baidu.cmsCommes.pojo.User;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Author: BSS
 * @create: 2020/6/18/9:10
 */
@Mapper
public interface UserDao {
    @Select("select * from t_user")
    List<User> userList();

    @Select("select count(*) from t_user")
    Integer countAll();

    @Select("select * from t_user where id = #{id}")
    @Results({@Result(property="id",column="id")
            ,@Result(property="create_date",column="create_date")
            ,@Result(property="email",column="email")
            ,@Result(property="nickname",column="nickname")
            ,@Result(property="password",column="password")
            ,@Result(property="phone",column="phone")
            ,@Result(property="status",column="status")
            ,@Result(property="username",column="username")
    })
    User selectUserById(@Param("id") Integer id);

    @Update("update t_user set create_date=#{user.create_date},email=#{user.email},nickname=#{user.nickname},password=#{user.password},phone=#{user.phone},status=#{user.status},username=#{user.username} where id=#{user.id}")
    Integer updateUser(@Param("user")User user);

    @Delete("delete from t_user where id = #{id}")
    Integer deleteUser(@Param("id") Integer id);

    @Insert("insert into t_user(create_date,email,nickname,password,phone,status,username)value(#{user.create_date},#{user.email},#{user.nickname},#{user.password},#{user.phone},#{user.status},#{user.username})")
    @Options(useGeneratedKeys = true,keyColumn = "t_user.id",keyProperty = "user.id")
    @ResultType(Integer.class)
    Integer saveUser(@Param("user") User user);
}
